//
// Created by ASUS on 24-4-16.
//

#include "SqStack.h"
#include <stdlib.h>


void SqStack_Init(SqStack *stack) {
    stack->top = -1;
}

int SqStack_Empty(const SqStack *stack) {
    if(stack->top == -1)
        return 1;
    return 0;
}

int SqStack_Push(SqStack *stack, ElemType data) {
    if(stack->top < MAX_SIZE-1) {
        stack->data[++stack->top] = data;
        return 1;
    }
    else
        return -1;
}

int SqStack_Pop(SqStack *stack, ElemType *e) {
    if(stack->top != -1) {
        // if(e == NULL) e = (ElemType*)malloc(sizeof(ElemType));
        *e = stack->data[stack->top--];
        return 1;
    }
    e = NULL;
    return -1;
}

ElemType SqStack_GetTop(const SqStack *stack) {
    if(stack->top != -1) {
        return stack->data[stack->top];
    }
    return -1;
}

void SqStack_Print(SqStack *s) {
    if(s->top == -1)
        printf("stack: NULL\n");
    else
        printf("stack: length: %d, topElem :%d\n",s->top+1, s->data[s->top]);
}
